﻿CreateGoogle(160,600,null,null,null,null,null,null,null,null);
var gPageIndex = 1;
//朋友号列表()
var FriendNoList = new Array();
//选中的朋友号
var CFNList = new Array();
//CheckBox标记(true全选操作，false针对朋友操作)
var CheckAOrF = false;
//父级窗口URL
var shareUrl=parent.location.toString();

function pageLoad(sender, args) 
{
    if(typeof(FriendPage) != "undefined")
    {
        if(FriendPage.RecordCount==0)
        {
            $get("NoFriends").style.display="";
            $get("SelectFriends").style.display="none";
        }
        else{
            RendPageNavigator(FriendPage,"divPage","GetPageFriend");
            if(typeof(FriendList) != "undefined")
            {
                RendFriendList(FriendList,"FriendsList");
            }
        }
    }
    //CreateValid1();
}

//获取页面数据（页索引）
function GetPageFriend(pageIndex)
{
	FriendNoList.length = 0;
    gPageIndex = pageIndex;
    showProgressBar(true);	
    InitDataFriend(gPageIndex);
}
//初始数据
function onsuccFriend(result)
{
    RendFriendList(result[0],"FriendsList");
    RendPageNavigator(result[1],"divPage","GetPageFriend");   
    showProgressBar(false);
}
//获取数据（页索引）
function InitDataFriend(pageIndex)
{   
    WebServices.User.Contacts.GetMemberFriends(Memberno,pageIndex,32,onsuccFriend);
}
function RendFriendList(list,divID)
{
    var domDiv =$get(divID);
    if(domDiv!=null)
    {    
        if(Sys.UI.DomElement.containsCssClass(domDiv, "DisplayNone"))
        {
            Sys.UI.DomElement.removeCssClass(domDiv, "DisplayNone");
        }         
        if($get("FriendsTemple")==null) return;        
        var item= $get("FriendsTemple").innerHTML;
        var listBuilder = new Sys.StringBuilder();
        var listCount = list.length;
        for (var index = 0; index < listCount; index++) 
        {
            var obj = list[index];                     
            var tmp = item.replace(/\$MemberNo\$/gi,obj.MemberNo).replace(/\$NickName\$/gi,obj.Nickname);            
            listBuilder.append(tmp); 
            FriendNoList[index] = obj.MemberNo;           
        }
        var sTemp = listBuilder.toString();
        domDiv.innerHTML = sTemp;
        for(var i = 0; i < listCount; i++)
        {
            var obj = list[i];
            if(CheckAOrF==true)
            {
                $get(obj.MemberNo).checked = $get("checkDel").checked;                
            }
            else
            {
                for(var j = 0; j < CFNList.length; j++)
                {
                    if(CFNList[j]==obj.MemberNo)
                    {
                        $get(obj.MemberNo).checked=true;
                    }
                }
            }                        
        }                   
    }
}
//显示（0:Send an Email，1:italki friends）
function ShowType(val)
{  
    if(val==0){        
        $get("askQuestype1").style.display="";
        $get("askQuestype2").style.display="none";
        $get("spanQuesType1").className="first selATags";
        $get("spanQuesType2").className="unselATags";
    }
    else if(val==1){
        $get("askQuestype1").style.display="none";
        $get("askQuestype2").style.display="";
        $get("spanQuesType1").className="first unselATags";
        $get("spanQuesType2").className="selATags";
    }
}
//全选与取消全选
function CheckAllBox(box)    
{ 
    CheckAOrF=true;
    var fmlist = FriendNoList.length;
    for(var i = 0; i < fmlist; i++)
    {
        $get(FriendNoList[i]).checked = box.checked;        
    }
    if(box.checked==true)
    {
        CFNList.length=0;
        for (var i = 0; i < AllFriendN.lengh;i++)
        {
            CFNList.push(AllFriendN[i][0]);
        }
        //CFNList = AllFriendN.slice(0);
    }
    else
    {
         CFNList.length=0;  
    }    
}
//朋友校验（朋友号）
function CheckFriend(friendNo,box)
{
    CheckAOrF=false;
    if(box.checked==true)
    {
        CFNList.push(friendNo);
    }
    else
    {
        $get("checkDel").checked=false;
        for(var i=0;i<CFNList.length;i++)
        {
            if(CFNList[i]==friendNo)
            {
                CFNList.splice(i,1);
            }
        }    
    }    
}
//发送邮件
function SendEmail()
{    
    //if(!validationForm(new validationOptions('Button1', '', true, ''))) return;
    var emails =  $get("txtEmail").value;
    if(emails=="")
    {
        $get("emOthErr").style.display="";
        return;
    }
    var mails = emails.replace(/,/gi,"<br/>").toString();
    $get("emOthErr").style.display="none";    
    $get("EmailCon").innerHTML=mails;
    $get("Send").style.display="none";
    $get("SendEmail1").style.display="";    
    WebServices.User.Contacts.SendMail(CNickName,emails,shareUrl);   
}
//发送italki 邮件
function SendItalkiMail()
{
    if(CFNList.length<=0)
    {
        $get("error1ID").style.display="";        
        return;
    }    
	$get("error1ID").style.display="none";
	var nickNames="";
	for(var i=0; i<CFNList.length; i++)
	{
	    for(var j=0;j<AllFriendN.length;j++)
	    {
	        if(CFNList[i]==AllFriendN[j][0])
	        {
	            nickNames+=AllFriendN[j][1]+"<br/>";
	            break;
	        }
	    }
	    //nickName+=$get(CFNList[i].toString()).value+"<br/>"
	}
	$get("FNickName").innerHTML = nickNames;
	$get("SelFriendsC").style.display="";
    $get("Send").style.display="none"; 	
    WebServices.User.Contacts.SendItalkiMail(CNickName,CFNList,shareUrl);
}

function onsuccOP(result)
{
    if(result.State) 
    {
        $get("Send").style.display="none"; 
        $get("Succeed").style.display="";
    }
    else
    {
        $get("Send").style.display="none"; 
        $get("failure").style.display="";
    }    
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();